<template>
  <view class="page-user-info">
    <van-cell-group>
      <van-cell title="头像">
        <van-image
            round
            width="60rpx"
            height="60rpx"
            :src="form.avatar"
          />
      </van-cell>
      <van-cell title="登录账号" :value="form.userName" />
      <van-cell title="绑定手机" :value="form.phone" />
    </van-cell-group>
    <view class="p-a-15">
      <van-button type="info" round block @tap="uploadAvatar">点击更换头像</van-button>
    </view>
  </view>
</template>

<script>
import { uploadImg } from '@/static/js/upload';
export default {
  data(){
    return{
      form:{
        avatar: null,
        userName: null,
        phone: null,
      }
    }
  },
  onShow(){
    this.getUserInfo();
  },
  methods:{
    getUserInfo(){
      this.$http('get', '/admin/user/info', {}, (data,msg) => {
        this.userInfo = data.sysUser;
        this.$utils.resetForm(this.form, data.sysUser);
      })
    },
    uploadAvatar() {
			uni.chooseImage({
				success: img => {
					let files = img.tempFiles
					this.avatar = files[0].path
					upLoadImg('/nursing-upms/file/upload',files[0].path).then(res => {
						let data = JSON.parse(res.data);
            let param = {
              username: this.form.username,
							avatar: data.data.fileName
            };
            this.$http('put', '/nursing-upms/user/edit', {}, (data,msg) => {
              uni.showToast({title: '修改成功', icon: 'none'});
              this.getUserIfno();
            });
					})
				},
        fail: res => {
          console.log(res);
        }
			})
		},
  }
}
</script>

<style>

</style>